package common.config.datasource;

import common.model.po.SysUser;
import common.util.ClassUtil;
import io.seata.common.exception.ShouldNeverHappenException;
import org.apache.shardingsphere.infra.database.DefaultSchema;

/**
 * 数据源相关的常量<p>
 * 其中数据源名称必须小写
 *
 * @author 米泽鹏
 * @since 2023-7-29 下午 7:07
 */
public class DataSourceConstants {

	public static final String ID_FIELD_NAME_IN_DATABASE = "id";

	public static final String OPERATOR_FIELD_NAME_IN_DATABASE = "operator";

	public static final String CREATE_TIME_FIELD_NAME_IN_DATABASE = "create_time";

	public static final String UPDATE_TIME_FIELD_NAME_IN_DATABASE = "update_time";

	public static final String ID_FIELD_NAME_IN_JAVA_ENTITY = ClassUtil.getFieldName(SysUser::getId);

	public static final String OPERATOR_FIELD_NAME_IN_JAVA_ENTITY = ClassUtil.getFieldName(SysUser::getOperator);

	public static final String CREATE_TIME_FIELD_NAME_IN_JAVA_ENTITY = ClassUtil.getFieldName(SysUser::getCreateTime);

	public static final String UPDATE_TIME_FIELD_NAME_IN_JAVA_ENTITY = ClassUtil.getFieldName(SysUser::getUpdateTime);

	/**
	 * ShardingSphere数据源：读写分离 + 分库分表
	 * 数据源名称必须设置为{@link DefaultSchema#LOGIC_NAME}，否则插入数据时报错{@link ShouldNeverHappenException}
	 */
	public static final String SHARDING_DATASOURCE = DefaultSchema.LOGIC_NAME;

	/**
	 * 慢查询日志数据源（代理）
	 */
	public static final String MYSQL_DATASOURCE = "mysql_proxy";

	/**
	 * information_schema数据源（代理）
	 */
	public static final String INFORMATION_SCHEMA_DATASOURCE = "informationSchema_proxy";

	/**
	 * master数据源（代理）
	 */
	public static final String MASTER_DATASOURCE = "master_proxy";

}
